package com.tvein.sanguo.action.view
{
	//flash
	import flash.events.StatusEvent;
	//pureMVC
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.mediator.FlashMediator;
	//custom
	import com.tvein.sanguo.action.common.GameConstants;
	import com.tvein.sanguo.Action;
	import com.tvein.sanguo.action.controller.system.SystemCommand;
	import com.tvein.sanguo.action.controller.login.LoginCommand;
	import com.tvein.sanguo.action.controller.role.RoleCommand;
	import com.tvein.sanguo.action.controller.menu.MenuCommand;
	import com.tvein.sanguo.action.controller.tool.ToolCommand;
	import com.tvein.sanguo.action.controller.skill.SkillCommand;
	import com.tvein.sanguo.action.controller.command.CommandCommand;
	import com.tvein.sanguo.action.controller.room.RoomCommand;
//
	public class ActionMediator extends FlashMediator
	{
		static public const NAME:String = "ActionMediator";
		
		public function ActionMediator(viewComponent:Object)
		{
			super(NAME, viewComponent);
		}
		
		public function get action():Action
		{
			return viewComponent as Action;
		}
		
		//Custom
		override public function onRegister() : void
        {
			facade.registerCommand(GameConstants.SYSTEM_COMMAND, SystemCommand);
			facade.registerCommand(GameConstants.LOGIN_COMMAND, LoginCommand);
			facade.registerCommand(GameConstants.ROLE_COMMAND, RoleCommand);
			facade.registerCommand(GameConstants.MENU_COMMAND, MenuCommand);
			facade.registerCommand(GameConstants.TOOL_COMMAND, ToolCommand);
			facade.registerCommand(GameConstants.SKILL_COMMAND, SkillCommand);
			facade.registerCommand(GameConstants.COMMAND_COMMAND, CommandCommand);
			facade.registerCommand(GameConstants.ROOM_COMMAND, RoomCommand);
        }
		
		public function _handleEvents(evt:Object):void
		{
			var params:Array = evt.type.split("-");
			
			switch(params[0])
			{
				case "System":
					sendNotification(GameConstants.SYSTEM_COMMAND, evt.cmd);
					break;
				case "Login":
					sendNotification(GameConstants.LOGIN_COMMAND, evt.cmd);
					break;
				case "Role":
					sendNotification(GameConstants.ROLE_COMMAND, evt.cmd);
					break;
				case "Menu":
					sendNotification(GameConstants.MENU_COMMAND, evt.cmd);
					break;
				case "Tool":
					sendNotification(GameConstants.TOOL_COMMAND, evt.cmd);
					break;
				case "Skill":
					sendNotification(GameConstants.SKILL_COMMAND, evt.cmd);
					break;
				case "Command":
					sendNotification(GameConstants.COMMAND_COMMAND, evt.cmd);
					break;
				case "Room":
					sendNotification(GameConstants.ROOM_COMMAND, evt.cmd);
					break;
			}
		}
	}
}